package com.GlobalPaint.app.Adapter;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.GlobalPaint.app.Base.BaseCommonAdapter;
import com.GlobalPaint.app.R;
import com.GlobalPaint.app.bean.PaletteDetailsBean;
import com.GlobalPaint.app.ui.HTML.tujiActivity;
import com.GlobalPaint.app.ui.Home.Palette.PaletterDetailsActivity;
import com.GlobalPaint.app.utils.Constants;
import com.GlobalPaint.app.utils.DataManager;
import com.squareup.picasso.Picasso;

import java.io.Serializable;
import java.util.List;

import static com.GlobalPaint.app.R.layout.palette_details_gridview;

/**
 * Created by Administrator on 2017/12/30 0030.
 */

public class paletteDetailsAdapter extends BaseCommonAdapter {

    private ImageView iv_icon;

    public paletteDetailsAdapter(PaletterDetailsActivity paletterDetailsActivity,
                                 int palette_details_gridview, List<PaletteDetailsBean.DataBean> list, int size) {
        super(paletterDetailsActivity,palette_details_gridview,list,size);

    }
    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        RelativeLayout list_item_layout =
                (RelativeLayout) LayoutInflater.from(context).inflate(palette_details_gridview, null);
        final PaletteDetailsBean.DataBean bean = (PaletteDetailsBean.DataBean) adapter_data.get(i);
        TextView tv_text = (TextView)list_item_layout. findViewById(R.id.tv_text);
        iv_icon = (ImageView)list_item_layout. findViewById(R.id.iv_icon);
        String Title=bean.getFTitle()== null?"":bean.getFTitle();

        String Url=bean.getFSmallImage()== null?"http://218.192.170.132/1.jpg":bean.getFSmallImage();
        tv_text.setText(Title);
        Picasso.with(context).load(Constants.JASON_SERVICE_Img+Url)
                .into(iv_icon);
        list_item_layout.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                PaletteDetailsBean.DataBean Bean =(PaletteDetailsBean.DataBean)adapter_data.get(i);
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putSerializable("serinfo", (Serializable) Bean);
                intent.putExtras(bundle);
                if(DataManager.typename.equals("图集")){
                    intent.setClass(context, tujiActivity.class);
                    intent.putExtras(bundle);
                    view.getContext().startActivity(intent);
                }

            }
        });

        return list_item_layout;


       }
}
